#coding:utf-8
from django.http import HttpResponse
from lovewith.account.models import MtUser
from lovewith.api.qiniu import Qiniu


# def convert_user_avatar(request):
#     uid = request.GET.get('uid')
#     content = 'done'
#     if not uid:
#         user_filter_data = MtUser.objects.all().order_by('id')[:2]
#     else:
#         user_filter_data = MtUser.objects.filter(id__gte=int(uid)).order_by('id')[:2]
#
#     if user_filter_data and user_filter_data.exists():
#         user_data = user_filter_data[0]
#         next_user_data = user_filter_data[1]
#
#         if user_data:
#             if user_data.avatar == 'http://s.lovewith.me/static/images/avatar.gif':
#                 user_data.avatar = 'http://avatar.etosun.com/avatar.gif'
#                 user_data.save()
#             else:
#                 if user_data.avatar.find('avatar.etosun.com') == -1:
#                     # 保存远程服务器图片
#                     avatar = Qiniu('mt-temp').save_remote(user_data.avatar, 'mt-avatar')
#                     user_data.avatar = avatar
#                     user_data.save()
#
#         if next_user_data:
#             content = '<script>setTimeout(function(){window.location.href="/u/convert/avatar/?uid=%s"}, 200)</script>' % next_user_data.id
#
#     return HttpResponse(content)